package org.rcloud.io.service.impl;

import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.SceneryMapper;
import org.rcloud.io.model.Rural;
import org.rcloud.io.model.Scenery;
import org.rcloud.io.service.SceneryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2019/3/12.
 */
@Service(value="SceneryService")
public class SceneryServiceImpl implements SceneryService{

    @Autowired
    private SceneryMapper sceneryMapper;

    @Override
    public PageVo<Scenery> findScenery() {

        try {
            List<Scenery> list = sceneryMapper.selectAll();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo findByEid(String eid) {

        try {
            Scenery scenery = sceneryMapper.selectByEid(eid);
            return ResultVo.setOK(scenery);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo saveScenery(Scenery scenery) {

        if (scenery.equals("") || scenery == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                sceneryMapper.insertSelective(scenery);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public ResultVo updateScenery(Scenery scenery) {

        if (scenery.equals("") || scenery == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                sceneryMapper.updateByPrimaryKeySelective(scenery);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public ResultVo findById(int id) {

        try {
            Scenery scenery = sceneryMapper.selectByPrimaryKey(id);
            return ResultVo.setOK(scenery);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

}
